package com.github.ylt.player;

import java.io.*;
import java.net.*;
import java.nio.ByteBuffer;
import java.nio.channels.*;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.Random;
import java.util.Set;

public class PlayerController {
    private final ProcessBuilder builder;
    private Process process;
    private OutputStream output;
    private BufferedWriter writer;
    private PlayerController(){
        builder = new ProcessBuilder("mpv","/home/wutong/视频/demo.mp4");
    }
    private static class PlayerControllerHolder {
        private static final PlayerController INSTANCE = new PlayerController();
    }
    public static PlayerController getInstance() {
        return PlayerControllerHolder.INSTANCE;
    }

    public void start() {
        try {
            process = builder.start();
            writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void stop() {
        try {
            builder.command("--pause");
            writer.write("\n");
            writer.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

    public static void main(String[] args) throws InterruptedException, IOException {
        Player instance = Player.getInstance();
        //
        // instance.start("/home/wutong/视频/11.mp4");
    }

}
